/****************************************************************************
 *
 *  DBASE3DS.H
 *
 *  (C) Copyright 1997 by Autodesk, Inc.
 *
 *  This program is copyrighted by Autodesk, Inc. and is licensed to you under
 *  the following conditions.  You may not distribute or publish the source
 *  code of this program in any form.  You may incorporate this code in object
 *  form in derivative works provided such derivative works are (i.) are de-
 *  signed and intended to work solely with Autodesk, Inc. products, and (ii.)
 *  contain Autodesk's copyright notice "(C) Copyright 1995 by Autodesk, Inc."
 *
 *  AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  AUTODESK SPE-
 *  CIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
 *  A PARTICULAR USE.  AUTODESK, INC.  DOES NOT WARRANT THAT THE OPERATION OF
 *  THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.
 *
 ***************************************************************************/

#ifndef DBASE_3DS_H
#define DBASE_3DS_H

#include "3DSTYPE.H"
#include "3DSFILE.H"
/* #include "3DSFTKST.H" */
#include "3DSERR.H"
#include "CHUNK3DS.H"

/* Database instance structure */

/* Used as a parameter to CreateNewDatabase3ds */

/* Private Typedefs */

/* dbtype3ds - Database type settings */
typedef enum
{
   Unknown,      /* Database has not be created yet */
   MeshFile,     /* 3D Studio .3DS file */
   ProjectFile,  /* 3D STudio .PRJ file */
   MaterialFile  /* 3D Studio .MLI file */
} dbtype3ds;
/* End Private */

/* Public Typedef */

/* database3ds - File database */
typedef struct
{
   chunk3ds *topchunk; /* top chunk in the file */
   byte3ds objlistdirty; /* If true, than *objlist needs to be recreated */
   byte3ds matlistdirty;
   byte3ds nodelistdirty;
   chunklist3ds *objlist; /* Quick Cross references between names and database chunks */
   chunklist3ds *matlist;
   chunklist3ds *nodelist;
} database3ds;
/* End Public */

/* Public Prototypes */

#ifdef __cplusplus
extern "C" {
#endif

/* Database functions */
void InitDatabase3ds(database3ds **db);
void ReleaseDatabase3ds(database3ds **db);
void CreateDatabase3ds(file3ds *file, database3ds *db);
void CreateNewDatabase3ds(database3ds *db, dbtype3ds type);
dbtype3ds GetDatabaseType3ds(database3ds *db);
void CopyDatabase3ds(database3ds *idb, database3ds *odb);
void DisconnectDatabase3ds(database3ds *db);
void WriteDatabase3ds(file3ds *file, database3ds *db);
/* End Public */

void UpdateNamedObjectList3ds(database3ds *db);
void FindNamedObject3ds(database3ds *db, char3ds *name, chunk3ds **found);
void MakeNamedObjectListDirty3ds(database3ds *db);
void UpdateMatEntryList3ds(database3ds *db);
void FindMatEntry3ds(database3ds *db, char3ds *name, chunk3ds **found);
chunk3ds *FindMatEntryByIndex3ds(database3ds *db, ulong3ds index);
void MakeMatEntryListDirty3ds(database3ds *db);
void ReadChildren3ds(chunk3ds *parent);
void ReadXDataEntryChildren3ds(chunk3ds *parent);
void WriteChunk3ds(chunk3ds *chunk, ubyte3ds fileindex);
void DeleteChunkTypeByIndex3ds(database3ds *db, chunktag3ds id, ulong3ds index);
void DeleteNamedObjectByName3ds(database3ds *db, char3ds *name);
chunk3ds *FindNamedObjectByIndex3ds(database3ds *db, chunktag3ds type, ulong3ds index);
void CopyNamedObjectByName3ds(database3ds *destdb, database3ds *srcdb, char3ds *name);
void CopyNamedObjectByIndex3ds(database3ds *destdb, database3ds *srcdb, chunktag3ds nobjtype, ulong3ds index);
void UpdateNodeTagList3ds(database3ds *db);
void MakeNodeTagListDirty3ds(database3ds *db);
chunk3ds *FindNodeTagByNameAndType3ds(database3ds *db, char3ds *name, chunktag3ds type);
chunk3ds *FindNodeTagByIndexAndType3ds(database3ds *db, ulong3ds index, chunktag3ds type);
void DeleteNodeTagByIndexAndType3ds(database3ds *db, ulong3ds index, chunktag3ds type);
void DeleteNodeTagByNameAndType3ds(database3ds *db, char3ds *name, chunktag3ds type);
void CopyNodeTagByIndexAndType3ds(database3ds *destdb, database3ds *srcdb, ulong3ds index, chunktag3ds type);
void CopyNodeTagByNameAndType3ds(database3ds *destdb, database3ds *srcdb, char3ds *name, chunktag3ds type);

#ifdef __cplusplus
}
#endif

#endif
